package com.atguigu.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.product.entity.McategoryEntity;
import com.atguigu.gulimall.product.service.McategoryService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 *
 *
 * @author cpc
 * @email 1728980597@qq.com
 * @date 2022-04-06 12:49:35
 */
@RestController
@RequestMapping("product/mcategory")
public class McategoryController {
    @Autowired
    private McategoryService mcategoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = mcategoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{categoryId}")
    public R info(@PathVariable("categoryId") Integer categoryId){
		McategoryEntity mcategory = mcategoryService.getById(categoryId);

        return R.ok().put("mcategory", mcategory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody McategoryEntity mcategory){
		mcategoryService.save(mcategory);
        return R.ok();
    }
//    @RequestMapping("/save")
//    public R save(@RequestBody McategoryEntity mcategory){
//        mcategoryService.saveMyCategory(mcategory);
//
//        return R.ok();
//    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody McategoryEntity mcategory){
		mcategoryService.updateById(mcategory);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] categoryIds){
		mcategoryService.removeByIds(Arrays.asList(categoryIds));

        return R.ok();
    }

}
